package com.media.publish.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;


import com.media.R;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @author:hanke 2022/4/28
 * desc:
 */
public class SharePosterPagerAdapter extends PagerAdapter {

    List<String> mPagerViewList = new ArrayList<>();
    Context mContext;

    public SharePosterPagerAdapter(Context context) {
        mContext = context;
    }

    public void setData(List<String> pagerViewList) {
        mPagerViewList = pagerViewList;
        notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return mPagerViewList.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
        return view == o;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.layout_share_poster_style, null);
        ImageView ivPoster = view.findViewById(R.id.iv_poster);
        File file = new File(mPagerViewList.get(position));
        ivPoster.setImageURI(Uri.fromFile(file));
        container.addView(view);
        return view;
    }


    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView((View) object);
    }

    @Override
    public float getPageWidth(int position) {
        return 1f;
    }

    @Override
    public int getItemPosition(@NonNull Object object) {
        return POSITION_NONE;
    }
}
